import 'package:fish_redux/fish_redux.dart';

import 'action.dart';
import 'state.dart';

Reducer<MePageState> buildReducer() {
  return asReducer(
    <Object, Reducer<MePageState>>{
      MePageAction.init: _init,
      MePageAction.login: _login,
    },
  );
}

MePageState _init(MePageState state, Action action) {
  final MePageState newState = state.clone();
  final MePageState payload = action.payload ?? MePageState();

  newState.isLogined = payload.isLogined;

  return newState;
}

MePageState _login(MePageState state, Action action) {
  final MePageState newState = state.clone();
  final bool payload = action.payload ?? false;

  newState.isLogined = payload;

  return newState;
}
